#ifndef MYOPENGLWIDGET_H
#define MYOPENGLWIDGET_H

#include <QVTKOpenGLNativeWidget.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <vtkSmartPointer.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkCellPicker.h>
#include <vtkPointPicker.h>

class vtkPoints;
class vtkPolyData;
class vtkCellArray;
class vtkVertexGlyphFilter;
class vtkPolyDataMapper;
class vtkActor;
class vtkRenderer;
class vtkTextActor;
class vtkAxesActor;
class vtkUnsignedCharArray;
class vtkCubeAxesActor;
class vtkPlaneSource;
class vtkInteractorStyleTrackballCamera;
class vtkCaptionActor2D;
class vtkTextProperty;

class MyOpenGLWidget : public QVTKOpenGLNativeWidget
{
    Q_OBJECT
public:
    MyOpenGLWidget(QWidget* parent = nullptr);

public slots:
    void updatePointCloud(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& cloud);
    void setColorByField(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& cloud, const std::string& field);

protected:
    void mousePressEvent(QMouseEvent* event) override;

private:
    void setupVTKPipeline();
    vtkSmartPointer<vtkRenderer> m_renderer;
    vtkSmartPointer<vtkRenderWindow> m_renderWindow;
    vtkSmartPointer<vtkTextActor> m_textActor; // 用于显示分辨率的文本演员
    vtkSmartPointer<vtkPoints> points;
    vtkSmartPointer<vtkUnsignedCharArray> colors; // 新增
    vtkSmartPointer<vtkPolyData> polydata;
    vtkSmartPointer<vtkCellArray> vertices;
    vtkSmartPointer<vtkPolyDataMapper> mapper;
    vtkSmartPointer<vtkActor> actor;
    vtkSmartPointer<vtkCubeAxesActor> cubeAxesActor;
    vtkSmartPointer<vtkPlaneSource> planeSource;
    //vtkSmartPointer<vtkCellPicker> picker;
    vtkSmartPointer<vtkPointPicker> picker;

    void initAxesSet();
    vtkSmartPointer<vtkAxesActor> axesActor;
    vtkCaptionActor2D* xCaption;
    vtkCaptionActor2D* yCaption;
    vtkCaptionActor2D* zCaption;
    vtkTextProperty* textXProp;
    vtkTextProperty* textYProp;
    vtkTextProperty* textZProp;
};

#endif // MYOPENGLWIDGET_H